package vsm.vsm_server.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vsm.vsm_server.pojo.Notice.Notice;
import vsm.vsm_server.pojo.Notice.NoticeVo;
import vsm.vsm_server.pojo.Result.Result;
import vsm.vsm_server.service.NoticeService;

import java.math.BigInteger;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/message")
@CrossOrigin
public class NoticeController {
    @Autowired
    NoticeService noticeService;
    @GetMapping("/all/{userId}")
    public Result<List<NoticeVo>> getAllNotice(@PathVariable BigInteger userId){
        List<NoticeVo>  noticeList = noticeService.getAllNotice(userId);
       return Result.success(noticeList);
    }

    @GetMapping("/exist/{userId}")
    public  Result<Boolean> existNewNotice(@PathVariable BigInteger userId){

        return Result.success(noticeService.getExistNew(userId));
    }

    @PostMapping("check/{userId}")
    public Result<String> checkNewNotice(@PathVariable BigInteger userId){
        log.info("用户：{}已查看新消息",userId);
        noticeService.checkNewNotice(userId);
        return Result.success();
    }
    @PostMapping("/send")
    public Result<String> saveNotice(@RequestBody Notice notice){
        log.info("用户：{}收到消息{}", notice.getUserId(), notice.toString());
        noticeService.saveNotice(notice);
        return Result.success();
    }

}
